home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
borland
/
prbgi097.zip
/
C.ZIP
/
TVBGI.CPP
< prev
next >
Wrap
Text File
|
1992-12-15
|
18KB
|
554 lines
/*---------------------------------------------------------*/
/* */
/* Turbo Vision 1.0 */
/* Turbo Vision BGI Support Demo */
/* Copyright (c) 1991 by Borland International */
/* */
/*---------------------------------------------------------*/
/*
Sorry, this is my first OOP (and Turbo Vision) program.
Andrzej Resztak
e-mail: Resztak@PLUMCS11.bitnet
*/
#define Uses_TKeys
#define Uses_TApplication
#define Uses_TEvent
#define Uses_TRect
#define Uses_TDialog
#define Uses_TButton
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TStatusItem
#define Uses_TStatusDef
#define Uses_TDeskTop
#define Uses_MsgBox
#define Uses_TChDirDialog
#define Uses_THistory
#define Uses_TWindow
#define Uses_TInputLine
#define Uses_TLabel
#define Uses_TSItem
#define Uses_TCheckBoxes
#define Uses_TCollection
#define Uses_TSystemError
#include <tv.h>
#include "Tvbgi.h"
#include <stdlib.h>
#include <graphics.h>
#include <string.h>
#include <strstrea.h>
#include <alloc.h>
#include <assert.h>
#include "tv2.h"
#include "prtgraph.h"
#include "BGIDEMO.H"
#if __BCPLUSPLUS__==0x0200
#error Sorry, this program seems to not work under BC++ 2.0.
#error I am new to OOP and Turbo Vision and don't know why.
#error The error has nothing common with PrintBGI package.
#error It just hangs up when (or after) choosing printer.
#error So if you want to use it under BC++ 2.0 change code
choosing printer.
#endif
unsigned _stklen=4096;
char pathToDrivers[MAXPATH] = ""; // Default location of *.BGI files
int _PRT__pascal TVUserPrtFunc( void far* UserPtr,
PRT__handleT *handlePPtr,
const char far* BGIpath );
static int StdBGI;
/*================*/
TBGIApp::TBGIApp() :
/*================*/
TProgInit( &TBGIApp::initStatusLine,
&TBGIApp::initMenuBar,
&TBGIApp::initDeskTop )
{ const char far *p=NULL;
if (*pathToDrivers==0) p = getenv("BGIPATH");
if ( p==NULL ) p = pathToDrivers;
strcpy(Options.bgiPath, p);
fexpand(Options.bgiPath);
Options.PicWidth = 4.0;
Options.PicHeight = 3.0;
Options.Preview=1;
StdBGI=Options.StdBGI=0;
Options.PrinterNo = Options.PRTModeNo = -1;
appDriver = DETECT;
appMode = 0;
if (graphAppInit(appDriver, appMode, Options.bgiPath, True) == False)
messageBox("Cannot load graphics driver.", mfError | mfOKButton);
PRT_LinkDrivers();
}
/*================*/
TBGIApp::~TBGIApp()
/*================*/
{
graphAppDone();
}
/*===================*/
void TBGIApp::newWin()
/*===================*/
{
static ushort winNum = 0;
TWindow *p;
TRect r(deskTop->getExtent());
r = TRect( winNum % (deskTop->size.y-1),
winNum % (deskTop->size.y-1),
deskTop->size.x,
deskTop->size.y);
char msgStr[10];
ostrstream os( msgStr, 10 );
os << "Window " << winNum << ends;
p = new TWindow( r, msgStr, 0 );
p->options |= ofTileable;
deskTop->insert( validView(p) );
winNum++;
}
int ScreenPreview=1;
/*========================================================================*/
void TBGIApp::doGraphics(int far Graphfunc(void far * UserPointer), void far* UserPointer)
/*========================================================================*/
{
char errorMsg[MAXSIZE];
ushort maxX,maxY;
static const int CLIP_ON=1;
if ( Options.StdBGI )
{ // Std. BGI driver and std. Borland example code
suspend();
if (graphicsStart() == False)
{
resume();
strcpy(errorMsg,grapherrormsg(graphresult()));
strcat( errorMsg,"." );
messageBox(errorMsg, mfError | mfOKButton);
}
else
{
maxX = getmaxx();
maxY = getmaxy();
outtextxy(0, (maxY - textheight("M")),
"Press any key to return...");
setviewport(0, 0, maxX - 1, (maxY - (textheight("M") + 5)), CLIP_ON);
Graphfunc(UserPointer);
graphicsStop();
resume();
}
}
else
{
static int PRTdrv=DETECT,PRTmode;
int ReturnCode;
unsigned oldhelpCtx;
PRT_LinkDrivers(); /* link drivers definitions into an executable code */
ReturnCode=PRT_SetDriver ( Options.PrinterNo+1, Options.PRTModeNo,
1000*Options.PicWidth, 1000*Options.PicHeight,
PRT_INVERSE );
if ( ReturnCode )
messageBox("Wrong printer or mode specified", mfError | mfOKButton);
else
{
ScreenPreview=Options.Preview;
PRT_SetOutName(Options.PrintDest);
PRT_SetUserPrintFunc(TVUserPrtFunc);
if ( PRTdrv==DETECT )
{
PRTmode=0;
/* If you want you may not linkining in the BitImage BGI driver into the */
/* EXE file. To do comment out following two lines. */
PRTdrv = PRT_installuserdriver ( "BitImage", NULL );
PRT_registerfarbgidriver ( BitImage );
PRT_SetHaltVariable((unsigned char *)&TSystemError::ctrlBreakHit);
}
oldhelpCtx = helpCtx;
helpCtx = hcGraphBuild;
TProgram::application->statusLine->update(); // change status line
TSystemError::ctrlBreakHit=0; // reset break indicator
ReturnCode = PRT_PrintBGI ( &PRTdrv,&PRTmode,Options.bgiPath,
Graphfunc, UserPointer );
helpCtx = oldhelpCtx;
TProgram::application->statusLine->update();
if ( ReturnCode )
messageBox(PRT_grapherrormsg(ReturnCode), mfError | mfOKButton);
}
}
}
/*-------------------------------------------------*/
void TEnumPrinter::newFocusedItem( ccIndex newItem )
/*-------------------------------------------------*/
{
TEnumValue::newFocusedItem(newItem);
if (EnumM!=NULL) EnumM->setModes(False);
}
/*----------------------------------------------*/
TEnumPrinter::TEnumPrinter(const TRect& bounds ):
TEnumValue(bounds,32)
/*----------------------------------------------*/
{ int maxl=0;
EnumM=NULL;
TStrCollection *PrinterNames= new TStrCollection ( PRT_MaxDriver(),PRT_MaxDriver() );
for ( int i=1; i<=PRT_MaxDriver(); i++ )
{ const char*s;
PRT_DriverName(i,&s);
if ( maxl<strlen(s) ) maxl=strlen(s);
PrinterNames->insert(newStr(s));
}
newList(PrinterNames,-1);
}
/*-----------------------------------------------------------------*/
TEnumMode::TEnumMode ( const TRect& bounds, const TEnumPrinter *EP ):
/*-----------------------------------------------------------------*/
TEnumValue( bounds,32 )
{
EnumP=EP;
setModes(False);
};
/*------------------*/
Boolean TEnumMode::setModes(Boolean errMsg)
/*------------------*/
{ int p;
p = EnumP->focusedItem;
if ( p<0 || p>=PRT_MaxDriver() )
{
if ( errMsg )
messageBox("You must specify printer first", mfError | mfOKButton);
return False;
}
else
{
int maxmode;
PRT_MaxMode(p+1,&maxmode);
TStrCollection *ModeNames= new TStrCollection ( maxmode+1,maxmode+1 );
for ( int i=0; i<=maxmode; i++ )
{ const char*s;
PRT_ModeName(p+1,i,&s);
ModeNames->insert(newStr(s));
}
newList(ModeNames,maxmode);
return True;
}
}
/*----------------------------------------------*/
void TEnumMode::MakeSelection()
/*----------------------------------------------*/
{
if ( setModes(True) )
TEnumValue::MakeSelection();
}
/*=======================*/
void TBGIApp::SetGraphOptions()
/*=======================*/
{
TDialog *d = new TDialog(TRect(0,0,55,17), "Graph options");